import { Component } from 'react';

class CustomInput extends Component {
  constructor(props) {
    super(props);
    this.state = {
      value: ''
    }
  }
  handleChange = (e) => {
    this.setState({
      value: e.target.value
    })
  }
  handleSubmit = (e) => {
    if (e.key === 'Enter' && this.state.value !== '') {
      this.props.addTodo(this.state.value);
      this.setState({
        value: ''
      })
    }
    
  }
  render() {
    return (
      <div>
        <input type="text" placeholder="please input..." value={this.state.value} onChange={this.handleChange} onKeyUp={this.handleSubmit}/>
        <button onClick={this.handleSubmit}>add</button>
      </div>
    )
  }
}
export default CustomInput;